{
 "cells": [
  {
   "cell_type": "markdown",
   "source": [
    "Chapter 09\n",
    "# 定义、使用“鸡”类\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "outputs": [],
   "source": [
    "# 创建了一个名为 \"Chicken\" 的类\n",
    "class Chicken:\n",
    "    def __init__(self, name, age, color, weight):\n",
    "        # 初始化对象的属性\n",
    "        # 设置实例变量self.name来存储小鸡名字\n",
    "        self.name = name\n",
    "        # 设置实例变量self.age来存储小鸡年龄\n",
    "        self.age = age\n",
    "        # 设置实例变量self.color来存储小鸡体色\n",
    "        self.color = color\n",
    "        # 设置实例变量self.weight来存储小鸡体重\n",
    "        self.weight = weight"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-08T21:06:11.561948Z",
     "end_time": "2024-07-08T21:06:11.574082Z"
    }
   }
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "==小鸡的名字==\n",
      "小红\n",
      "==小鸡的年龄，yr==\n",
      "1\n",
      "==小鸡的颜色==\n",
      "黄色\n",
      "==小鸡的体重，kg==\n",
      "1.5\n"
     ]
    }
   ],
   "source": [
    "# 调用Chicken类\n",
    "chicken_01 = Chicken(\"小红\", 1, \"黄色\", 1.5)\n",
    "chicken_02 = Chicken(\"小黄\", 1.2, \"红色\", 2)\n",
    "print('==小鸡的名字==')\n",
    "print(chicken_01.name)\n",
    "print('==小鸡的年龄，yr==')\n",
    "print(chicken_01.age)\n",
    "print('==小鸡的颜色==')\n",
    "print(chicken_01.color)\n",
    "print('==小鸡的体重，kg==')\n",
    "print(chicken_01.weight)"
   ],
   "metadata": {
    "collapsed": false,
    "ExecuteTime": {
     "start_time": "2024-07-08T21:07:44.991916Z",
     "end_time": "2024-07-08T21:07:45.015118Z"
    }
   }
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 0
}
